// pages/home/home.js
import { showText } from "@/utils/util"
import { getIdeaShareStatusReq } from '@/api/task/ideaShare.service'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUri: getApp().globalData.imgUri,
    current: 0,
    previous: 0,
    next: 0,
    image_list: [{
      image: 1,
      url: '/pages/salon/salon',
      name: '高端沙龙'
    },
    {
      image: 2,
      url: '/shop/index/index',
      name: '积分商城'
    },
    {
      key: 'ideaShare',
      image: 3,
      url: '/pages/ideaShare/form/form',
      name: '心得分享'
    },
    {
      image: 4,
      url: '',
      name: '专家1V1'
    },
    {
      image: 5,
      url: '',
      name: '倾选送好礼'
    }
    ],
    image_class_list: [{
      class: '',
      is_see: 1,
      zIndex: 1
    },
    {
      class: '',
      is_see: 0,
      zIndex: 0
    },
    {
      class: '',
      is_see: 0,
      zIndex: -1
    },
    {
      class: '',
      is_see: 0,
      zIndex: -2
    },
    {
      class: '',
      is_see: 0,
      zIndex: -3
    }
    ],
    image_big_height: 0,
    init: 0,
    init_top: 0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getSystemInfo();
    var t = this;
  },
  bindchange(e) {
    let t = this;
    var cu = e.detail.current;
    var last_cu = t.data.current;
    var image_class_list = t.data.image_class_list;
    image_class_list[cu].is_see = 1;
    t.setData({
      current: cu,
      init: 1,
      image_class_list: image_class_list,
    });
  },
  goToUrl(e) {
    const data = this.data.image_list[this.data.current];
    if (data.key == 'ideaShare') {
      getIdeaShareStatusReq().then((res) => {
        if (res.code == 200) {
          if (res.data.todayCanSubmit) wx.navigateTo({
            url: data.url
          })
          else wx.navigateTo({
            url: '/pages/ideaShare/audit/audit'
          })
        }
      })
    }
    else if (data.url) {
      wx.navigateTo({
        url: data.url
      })
    } else {
      showText('您好，该活动暂未开始，敬请期待！')
    }
  },
  back() {
    wx.navigateBack()
  },
  getSystemInfo() {
    let t = this;
    wx.getSystemInfo({
      success: res => {
        var w = res.windowWidth;
        var h = res.windowHeight;
        var previous = w * (89 / 320);
        var next = w * (84 / 320);
        var image_big_height = w * (2000 / 1498);
        this.setData({
          previous: previous,
          next: next,
          image_big_height: image_big_height,
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: getApp().globalData.share_title,
      path: getApp().globalData.share_url,
      imageUrl: getApp().globalData.share_image,
    }
  }
})